package interfacekeyword;

/**
 * @License: (C) Copyright 2013-2022
 * @Contact: abcque@outlook.com
 * @IDE: IntelliJ IDEA
 * @Encoding: utf-8
 * @Project: st2214st2215
 * @Package: interfacekeyword
 * @File: ComparableRectangle.java
 * @Time: 2023/3/28 15:06
 * @Author: abcque
 * @Description:
 * @Modifier:
 * @ModifyDate:
 * @ModifyRemark:
 */
public class ComparableRectangle extends Rectangle implements CompareObject {

    public ComparableRectangle(double width, double height) {
        super(width, height);
    }

    /**
     * 比较两个对象的大小
     *
     * @param o
     * @return 0 相等，1 当前对象大，-1 当前对象小
     */
    @Override
    public int compareTo(Object o) {
        Rectangle rectangle = (Rectangle) o;

        if (getArea() == rectangle.getArea()){
            return 0;
        }
        else {
            if (getArea() > rectangle.getArea()){
                return 1;
            }
            else {
                return -1;
            }
        }
    }
}
